package tree;

import base.TreeNode;

import java.util.ArrayList;
import java.util.List;

public class InorderTraversal {
    private void traverse(TreeNode root, List<Integer> list) {
        if (root != null) {
            traverse(root.getLeft(), list);
            list.add(root.getVal());
            traverse(root.getRight(), list);
        }
    }
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> result = new ArrayList<>();
        traverse(root, result);
        return result;
    }
}
